import 'package:flutter/material.dart';

class TabBarTopDemo extends StatefulWidget {
  TabBarTopDemo({Key key}) : super(key: key);

  _TabBarTopDemoState createState() => _TabBarTopDemoState();
}

class _TabBarTopDemoState extends State<TabBarTopDemo> {
  final List<Tab> myTabs = <Tab>[
    new Tab(text: '语文'),
    new Tab(text: '数学'),
    new Tab(text: '英语'),
    new Tab(text: '化学'),
    new Tab(text: '物理'),
    new Tab(text: '政治'),
    new Tab(text: '经济'),
    new Tab(text: '体育'),
    new Tab(text: '音乐'),
    new Tab(text: '生物'),
  ];
  @override
  Widget build(BuildContext context) {
    return new DefaultTabController(
      length: myTabs.length,
      child: Scaffold(
        appBar: AppBar(
          title: Text('TabBarTopDemo'),
          bottom: new TabBar(
            tabs: myTabs,
            isScrollable: true,
            // 可以定义激活形状
            // indicator: new ShapeDecoration(
            //   color: Colors.black,
            //   shape: new Border.all(color: Colors.black, width: 1.0),
            // ),
            indicatorColor: Colors.black,
            // 指示器横线的高度
            indicatorWeight: 2.0,
            // 指示器横线的padding值
            // indicatorPadding: EdgeInsets.only(bottom: 3.0),
            indicatorSize: TabBarIndicatorSize.label,
          ),
        ),
        body: Container(
          color: Colors.lightGreen,
          child: new TabBarView(
            children: myTabs.map((Tab tab) {
              return new Center(child: new Text(tab.text));
            }).toList(),
          ),
        ),
      ),
    );
  }
}
